package com.study.sxc.service;

import com.study.sxc.Dao.IMachineDao;
import com.study.sxc.Entity.Machine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class machineService {

    private static final Logger log = LoggerFactory.getLogger(machineService.class);

    @Resource
    IMachineDao machineDao;

    public List<Machine> getMachines(List<Integer> ids) {
        log.info("查询机器列表，参数：{}", ids);
        List<Machine> machines = machineDao.getMachines(ids);
        log.info("DAO层返回数据：{}", machines);
        if(machines == null || machines.isEmpty()) {
            return new ArrayList<>();
        }
        return machines;
    }

    public int addMachine(Machine machine) {
        log.info("新增机器，参数：{}", machine);
        int result = machineDao.addMachine(machine);
        log.info("新增机器结果：{}", result);
        return result;
    }

    public int updateMachine(Machine machine) {
        log.info("更新机器，参数：{}", machine);
        int result = machineDao.updateMachine(machine);
        log.info("更新机器结果：{}", result);
        return result;
    }

    public int deleteMachine(Integer id) {
        log.info("删除机器，参数：{}", id);
        int result = machineDao.deleteMachine(id);
        log.info("删除机器结果：{}", result);
        return result;
    }

    public Machine getMachineById(Integer id) {
        return machineDao.getMachineById(id);
    }

    /**
     * 查询所有机器
     */
    public List<Machine> getAllMachines() {
        log.info("查询所有机器");
        List<Machine> machines = machineDao.getAllMachines();
        log.info("DAO层返回数据：{}", machines);
        if(machines == null || machines.isEmpty()) {
            return new ArrayList<>();
        }
        return machines;
    }
} 